package com.lb.shopguide.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lb.shopguide.R;
import com.lb.shopguide.entity.recommend.ActivityBannerBean;
import com.lb.shopguide.util.pic.ImageLoaderUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * Create by kangzhao on 2018/12/19
 */
public class AdapterRecActivity extends BaseQuickAdapter<ActivityBannerBean, BaseViewHolder> {
    public AdapterRecActivity(int layoutResId, @Nullable List<ActivityBannerBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ActivityBannerBean item) {
        View view = helper.itemView;
        ImageView ivImgBg = view.findViewById(R.id.iv_rec_activity_bg);
        TextView tvJoin = view.findViewById(R.id.tv_join);
        ProgressBar progressBar = view.findViewById(R.id.progress_bar);
        TextView tvProgress = view.findViewById(R.id.tv_progress);
        RelativeLayout layoutFinish = view.findViewById(R.id.layout_finish);

        ImageLoaderUtils.displayRound(mContext, ivImgBg, item.getSbActPicUrl(), 4);
        progressBar.setVisibility(View.GONE);
        tvProgress.setVisibility(View.GONE);
        tvJoin.setVisibility(View.GONE);
        layoutFinish.setVisibility(View.GONE);
        if (item.getActivityStatus() == ActivityBannerBean.ACTIVITY_RUNNING) {
            if (item.getCurrentActPercentNum() == 0) {
                tvJoin.setVisibility(View.VISIBLE);
            } else {
                if (item.getActPercentNum() == item.getCurrentActPercentNum()) {
                    layoutFinish.setVisibility(View.VISIBLE);
                } else {
                    double percent = new BigDecimal((float) item.getCurrentActPercentNum() / item.getActPercentNum()*100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    progressBar.setProgress((int) Math.round(percent));
                    progressBar.setVisibility(View.VISIBLE);
                    tvProgress.setText("已完成" + percent  + "%");
                    tvProgress.setVisibility(View.VISIBLE);
                }
            }
        } else if (item.getActivityStatus() == ActivityBannerBean.ACTIVITY_SHOW_DATA) {

        }
    }
}
